namespace Model.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class CreateNewDatabase : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.Attachment",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        FileName = c.String(),
                        Content = c.Binary(),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Configuration",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Key = c.String(),
                        Value = c.String(),
                        Created = c.DateTime(),
                        CreatedByUserId = c.Int(),
                        Modified = c.DateTime(),
                        ModifiedByUserId = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.User", t => t.CreatedByUserId)
                .ForeignKey("dbo.User", t => t.ModifiedByUserId)
                .Index(t => t.CreatedByUserId)
                .Index(t => t.ModifiedByUserId);
            
            CreateTable(
                "dbo.User",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        FirstName = c.String(),
                        LastName = c.String(),
                        Username = c.String(),
                        Password = c.String(),
                        Mobile = c.String(),
                        Type = c.String(),
                        AdditionalInformation = c.String(),
                        FullName = c.String(),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Customer",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        FullName = c.String(),
                        FirstName = c.String(),
                        LastName = c.String(),
                        Address1 = c.String(),
                        Address2 = c.String(),
                        City = c.String(),
                        PostalCode = c.String(),
                        Tel = c.String(),
                        Mobile1 = c.String(),
                        Mobile2 = c.String(),
                        Email1 = c.String(),
                        Email2 = c.String(),
                        Delivery = c.Int(),
                        OtherInformation = c.String(),
                        Created = c.DateTime(),
                        CreatedByUserId = c.Int(),
                        Modified = c.DateTime(),
                        ModifiedByUserId = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.User", t => t.CreatedByUserId)
                .ForeignKey("dbo.User", t => t.ModifiedByUserId)
                .Index(t => t.CreatedByUserId)
                .Index(t => t.ModifiedByUserId);
            
            CreateTable(
                "dbo.Delivery",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        DeliveryNo = c.String(),
                        DeliveryDate = c.DateTime(nullable: false),
                        VehicleId = c.Int(),
                        StartTime = c.DateTime(nullable: false),
                        OtherInformation = c.String(),
                        Status = c.String(),
                        Created = c.DateTime(),
                        CreatedByUserId = c.Int(),
                        Modified = c.DateTime(),
                        ModifiedByUserId = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.User", t => t.CreatedByUserId)
                .ForeignKey("dbo.User", t => t.ModifiedByUserId)
                .ForeignKey("dbo.Vehicle", t => t.VehicleId)
                .Index(t => t.VehicleId)
                .Index(t => t.CreatedByUserId)
                .Index(t => t.ModifiedByUserId);
            
            CreateTable(
                "dbo.Vehicle",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(),
                        Type = c.String(),
                        LicensePlate = c.String(),
                        Created = c.DateTime(),
                        CreatedByUserId = c.Int(),
                        Modified = c.DateTime(),
                        ModifiedByUserId = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.User", t => t.CreatedByUserId)
                .ForeignKey("dbo.User", t => t.ModifiedByUserId)
                .Index(t => t.CreatedByUserId)
                .Index(t => t.ModifiedByUserId);
            
            CreateTable(
                "dbo.Email",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(),
                        Content = c.String(),
                        Created = c.DateTime(),
                        CreatedByUserId = c.Int(),
                        Modified = c.DateTime(),
                        ModifiedByUserId = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.User", t => t.CreatedByUserId)
                .ForeignKey("dbo.User", t => t.ModifiedByUserId)
                .Index(t => t.CreatedByUserId)
                .Index(t => t.ModifiedByUserId);
            
            CreateTable(
                "dbo.OrderDetail",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        OrderId = c.Int(),
                        ProductId = c.Int(),
                        Quantity = c.Int(nullable: false),
                        ProductPrice = c.Decimal(nullable: false, precision: 18, scale: 2),
                        Total = c.Decimal(nullable: false, precision: 18, scale: 2),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Product", t => t.ProductId)
                .ForeignKey("dbo.Order", t => t.OrderId)
                .Index(t => t.OrderId)
                .Index(t => t.ProductId);
            
            CreateTable(
                "dbo.Product",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(),
                        Price = c.Decimal(nullable: false, precision: 18, scale: 2),
                        ProductTypeId = c.Int(),
                        Created = c.DateTime(),
                        CreatedByUserId = c.Int(),
                        Modified = c.DateTime(),
                        ModifiedByUserId = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.User", t => t.CreatedByUserId)
                .ForeignKey("dbo.User", t => t.ModifiedByUserId)
                .ForeignKey("dbo.ProductType", t => t.ProductTypeId)
                .Index(t => t.ProductTypeId)
                .Index(t => t.CreatedByUserId)
                .Index(t => t.ModifiedByUserId);
            
            CreateTable(
                "dbo.ProductType",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(),
                        Created = c.DateTime(),
                        CreatedByUserId = c.Int(),
                        Modified = c.DateTime(),
                        ModifiedByUserId = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.User", t => t.CreatedByUserId)
                .ForeignKey("dbo.User", t => t.ModifiedByUserId)
                .Index(t => t.CreatedByUserId)
                .Index(t => t.ModifiedByUserId);
            
            CreateTable(
                "dbo.Order",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        OrderId = c.String(),
                        CustomerId = c.Int(),
                        OrderDate = c.DateTime(nullable: false),
                        DeliveryDate = c.DateTime(nullable: false),
                        DeliveryAddress = c.String(),
                        OtherInformation = c.String(),
                        Status = c.String(),
                        Created = c.DateTime(),
                        CreatedByUserId = c.Int(),
                        Modified = c.DateTime(),
                        ModifiedByUserId = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.User", t => t.CreatedByUserId)
                .ForeignKey("dbo.Customer", t => t.CustomerId)
                .ForeignKey("dbo.User", t => t.ModifiedByUserId)
                .Index(t => t.CustomerId)
                .Index(t => t.CreatedByUserId)
                .Index(t => t.ModifiedByUserId);
            
            CreateTable(
                "dbo.Role",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(),
                        Created = c.DateTime(),
                        CreatedByUserId = c.Int(),
                        Modified = c.DateTime(),
                        ModifiedByUserId = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.User", t => t.CreatedByUserId)
                .ForeignKey("dbo.User", t => t.ModifiedByUserId)
                .Index(t => t.CreatedByUserId)
                .Index(t => t.ModifiedByUserId);
            
            CreateTable(
                "dbo.Sms",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(),
                        Content = c.String(),
                        Created = c.DateTime(),
                        CreatedByUserId = c.Int(),
                        Modified = c.DateTime(),
                        ModifiedByUserId = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.User", t => t.CreatedByUserId)
                .ForeignKey("dbo.User", t => t.ModifiedByUserId)
                .Index(t => t.CreatedByUserId)
                .Index(t => t.ModifiedByUserId);
            
        }
        
        public override void Down()
        {
            DropForeignKey("dbo.Sms", "ModifiedByUserId", "dbo.User");
            DropForeignKey("dbo.Sms", "CreatedByUserId", "dbo.User");
            DropForeignKey("dbo.Role", "ModifiedByUserId", "dbo.User");
            DropForeignKey("dbo.Role", "CreatedByUserId", "dbo.User");
            DropForeignKey("dbo.Order", "ModifiedByUserId", "dbo.User");
            DropForeignKey("dbo.OrderDetail", "OrderId", "dbo.Order");
            DropForeignKey("dbo.Order", "CustomerId", "dbo.Customer");
            DropForeignKey("dbo.Order", "CreatedByUserId", "dbo.User");
            DropForeignKey("dbo.OrderDetail", "ProductId", "dbo.Product");
            DropForeignKey("dbo.Product", "ProductTypeId", "dbo.ProductType");
            DropForeignKey("dbo.ProductType", "ModifiedByUserId", "dbo.User");
            DropForeignKey("dbo.ProductType", "CreatedByUserId", "dbo.User");
            DropForeignKey("dbo.Product", "ModifiedByUserId", "dbo.User");
            DropForeignKey("dbo.Product", "CreatedByUserId", "dbo.User");
            DropForeignKey("dbo.Email", "ModifiedByUserId", "dbo.User");
            DropForeignKey("dbo.Email", "CreatedByUserId", "dbo.User");
            DropForeignKey("dbo.Delivery", "VehicleId", "dbo.Vehicle");
            DropForeignKey("dbo.Vehicle", "ModifiedByUserId", "dbo.User");
            DropForeignKey("dbo.Vehicle", "CreatedByUserId", "dbo.User");
            DropForeignKey("dbo.Delivery", "ModifiedByUserId", "dbo.User");
            DropForeignKey("dbo.Delivery", "CreatedByUserId", "dbo.User");
            DropForeignKey("dbo.Customer", "ModifiedByUserId", "dbo.User");
            DropForeignKey("dbo.Customer", "CreatedByUserId", "dbo.User");
            DropForeignKey("dbo.Configuration", "ModifiedByUserId", "dbo.User");
            DropForeignKey("dbo.Configuration", "CreatedByUserId", "dbo.User");
            DropIndex("dbo.Sms", new[] { "ModifiedByUserId" });
            DropIndex("dbo.Sms", new[] { "CreatedByUserId" });
            DropIndex("dbo.Role", new[] { "ModifiedByUserId" });
            DropIndex("dbo.Role", new[] { "CreatedByUserId" });
            DropIndex("dbo.Order", new[] { "ModifiedByUserId" });
            DropIndex("dbo.Order", new[] { "CreatedByUserId" });
            DropIndex("dbo.Order", new[] { "CustomerId" });
            DropIndex("dbo.ProductType", new[] { "ModifiedByUserId" });
            DropIndex("dbo.ProductType", new[] { "CreatedByUserId" });
            DropIndex("dbo.Product", new[] { "ModifiedByUserId" });
            DropIndex("dbo.Product", new[] { "CreatedByUserId" });
            DropIndex("dbo.Product", new[] { "ProductTypeId" });
            DropIndex("dbo.OrderDetail", new[] { "ProductId" });
            DropIndex("dbo.OrderDetail", new[] { "OrderId" });
            DropIndex("dbo.Email", new[] { "ModifiedByUserId" });
            DropIndex("dbo.Email", new[] { "CreatedByUserId" });
            DropIndex("dbo.Vehicle", new[] { "ModifiedByUserId" });
            DropIndex("dbo.Vehicle", new[] { "CreatedByUserId" });
            DropIndex("dbo.Delivery", new[] { "ModifiedByUserId" });
            DropIndex("dbo.Delivery", new[] { "CreatedByUserId" });
            DropIndex("dbo.Delivery", new[] { "VehicleId" });
            DropIndex("dbo.Customer", new[] { "ModifiedByUserId" });
            DropIndex("dbo.Customer", new[] { "CreatedByUserId" });
            DropIndex("dbo.Configuration", new[] { "ModifiedByUserId" });
            DropIndex("dbo.Configuration", new[] { "CreatedByUserId" });
            DropTable("dbo.Sms");
            DropTable("dbo.Role");
            DropTable("dbo.Order");
            DropTable("dbo.ProductType");
            DropTable("dbo.Product");
            DropTable("dbo.OrderDetail");
            DropTable("dbo.Email");
            DropTable("dbo.Vehicle");
            DropTable("dbo.Delivery");
            DropTable("dbo.Customer");
            DropTable("dbo.User");
            DropTable("dbo.Configuration");
            DropTable("dbo.Attachment");
        }
    }
}
